package com.yuandian.management.controller;

import com.yuandian.api.management.validate.DeleteFlag;
import com.yuandian.api.management.validate.InsertFlag;
import com.yuandian.api.management.validate.UpdateFlag;
import com.yuandian.api.management.vo.EndToEndNodeVo;
import com.yuandian.api.management.vo.EndToEndRelationshipVo;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.management.service.ConfEndToEndRelationshipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.groups.Default;
import java.util.List;


/**
 * @author EDY
 */
@Slf4j
@Api(tags = "业务监控配置-业务步骤配置-端到端配置")
@RestController
@RequiredArgsConstructor
@RequestMapping("/step/endToEndRelationship")
public class ConfEndToEndRelationshipController {

	private final ConfEndToEndRelationshipService confEndToEndRelationshipService;

	/**
	 * 获取步骤端到端关系
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "获取步骤端到端关系", notes = "获取步骤端到端关系")
	@PostMapping("/getEndToEndRelationship")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessCode", value = "所属业务编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "stepCode", value = "步骤编码", paramType = "body", required = true, dataType = "String"),
	})
	public R<List<EndToEndNodeVo>> getEndToEndRelationship(@Validated @RequestBody @ApiIgnore EndToEndRelationshipVo endToEndRelationshipVo) {
		return R.ok(confEndToEndRelationshipService.getEndToEndRelationship(endToEndRelationshipVo));
	}

	/**
	 * 添加新节点
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "添加新节点", notes = "添加新节点")
	@PostMapping("/addNode")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessCode", value = "所属业务编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "stepCode", value = "步骤编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "resourceCode", value = "父资源节点资源编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "locationX", value = "坐标x", paramType = "body", required = true, dataType = "Double"),
			@ApiImplicitParam(name = "locationY", value = "坐标y", paramType = "body", required = true, dataType = "Double"),
			@ApiImplicitParam(name = "parentNodeId", value = "父节点id", paramType = "body", required = true, dataTypeClass = String.class),
			@ApiImplicitParam(name = "segmentId", value = "网端id", paramType = "body", required = true, dataTypeClass = Integer.class),
	})
	public R<String> addNode(@Validated({InsertFlag.class, Default.class}) @RequestBody @ApiIgnore  EndToEndRelationshipVo endToEndRelationshipVo) {
		return R.ok(confEndToEndRelationshipService.addNode(endToEndRelationshipVo));
	}

	/**
	 * 删除节点
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "删除节点", notes = "删除节点")
	@DeleteMapping("/removeNode")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessCode", value = "所属业务编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "stepCode", value = "步骤编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "nodeId", value = "当前节点nodeId", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isRecursiveDelete", value = "是否递归删除，默认false", paramType = "body", required = false, dataType = "String"),
	})
	public R<String> removeNode(@Validated({DeleteFlag.class, Default.class}) @RequestBody @ApiIgnore EndToEndRelationshipVo endToEndRelationshipVo) {
		return confEndToEndRelationshipService.removeNode(endToEndRelationshipVo);
	}

	/**
	 * 移动节点位置
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "移动节点位置", notes = "移动节点位置")
	@PostMapping("/updateNodeLocation")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "所属系统id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "businessCode", value = "所属业务编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "stepCode", value = "步骤编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "nodeId", value = "node节点id", paramType = "body", required = true, dataTypeClass = String.class),
			@ApiImplicitParam(name = "locationX", value = "坐标x", paramType = "body", required = true, dataType = "Double"),
			@ApiImplicitParam(name = "locationY", value = "坐标y", paramType = "body", required = true, dataType = "Double"),
	})
	public R<String> updateNodeLocation(@Validated({UpdateFlag.class, Default.class}) @RequestBody @ApiIgnore EndToEndRelationshipVo endToEndRelationshipVo) {
		return confEndToEndRelationshipService.updateNodeLocation(endToEndRelationshipVo);
	}


	/**
	 *
	 * 根据系统id找到所有的端到到端的关系
	 */
	@ApiIgnore
	@PostMapping("/getEndToEndRelationBySystemId/{systemId}")
	public R<List<EndToEndNodeVo>> getEndToEndRelationBySystemId(@PathVariable("systemId") Integer systemId) {
		return R.ok(confEndToEndRelationshipService.getEndToEndRelationBySystemId(systemId));
	}

}
